<!DOCTYPE html>
<html lang="en"xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>会员查询</title>
<base href="/SSMSD/">
<!-- <link rel="stylesheet" href="assets/css/bootstrap.min.css" />
<link rel="stylesheet" href="assets/font-awesome/4.2.0/css/font-awesome.min.css" />
<link rel="stylesheet" href="assets/fonts/fonts.googleapis.com.css" />
<link rel="stylesheet" href="assets/css/ace.min.css" />
<link rel="stylesheet" href="assets/css/ace-rtl.min.css" /> -->
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="assets/js/jquery.2.1.1.min.js"></script>
<style type="text/css">
.inputinfo{
	margin-top: 15px;
	margin-bottom: 15px;
}
</style>
<script type="text/javascript">
	$(function(){
		//更新折扣
		$("#updatediscount").click(function(){
			var newDiscount=$("#newDiscount").val();
			if(newDiscount<0||newDiscount>1||newDiscount==''){
				$("#info_d").html("折扣输入有误")
			}else{
				$.ajax({
					url:"setting/modifyVip",
					type:"put",
					data:{
						id:$("#vip_id_dm").val(),
						"vip.discout":newDiscount
					},
					success:function(result){
						if(result.code==200){
							alert("更新成功");
							findCustomer();
						}else{
							alert(result.massage);
						}
					}
				});
			}
		});
		
		//更新手机号码
		$("#updatePhone").click(function(){
			var newPhone=$("#newPhone").val();
			alert(newPhone);
			if(!newPhone.match(new RegExp("^[1][13579][0-9]{9}"))){
				$("#info_d").html("手机格式输入有误")
			}else{
				$.ajax({
					url:"customer/updatePhone",
					type:"put",
					data:{
						currentPhone:$("#currentPhone").val(),
						newPhone:$("#newPhone").val()
					},
					success:function(result){
						if(result.code==200){
							alert("更新成功");
							findCustomer();
						}else{
							alert(result.massage);
						}
					}
				});
			}
		});
		//创建会员
		$("#submit_m").click(function(){
			$.ajax({
				url:"setting/addVip",
				type:"post",
				data:{
					id:$("#vip_id_m").val()
				},
				success:function(result){
					if(result.code=200){
						alert("修改成功");
						findCustomer();
					}else{
						alert(result.massage);
					}
				}
			});
		});
		
		//查询会员等级
		$.ajax({
			url:"setting/getLevel",
			type:"get",
			success:function(result){
				if(result.code==200){
					var content="<option value=''></option>";
					for(var i=0;i<result.object.length;i++){
						content+="<option value="+result.object[i].id+">"+result.object[i].name+"</option>"
					}
					$("#vip_level").html(content);
					//$("#vip_level_m").html(content);
				}else{
					alert(result.massage);
				}
			}
		});
		
		//查询
		$("#searchCustomer").click(function(){
			findCustomer();
		});
		$("#nextPage").click(function(){
			var tpage=parseInt($("#totalPage").html());
			var cpage=parseInt($("#currentPage").html());
			if(tpage>cpage){
				$("#currentPage").html(cpage+1);
				findCustomer();
			}
		});
		$("#prePage").click(function(){
			var cpage=parseInt($("#currentPage").html());
			if(cpage>1){
				$("#currentPage").html(cpage-1);
				findCustomer();
			}
		});
		$("#firstPage").click(function(){
			var cpage=parseInt($("#currentPage").html());
			if(cpage!=1){
				$("#currentPage").html(1);
				findCustomer();
			}
				
		});
		$("#lastPage").click(function(){
			var tpage=parseInt($("#totalPage").html());
			var cpage=parseInt($("#currentPage").html());
			if(tpage!=cpage&&!isNaN(tpage)){
				$("#currentPage").html(tpage);
				findCustomer();
			}
		});
	});
	function findCustomer(){
		$.ajax({
			url:"/SSMSD/customer/findCustomer",
			type:"get",
			data:{
				"customer.name":$("#vip_name").val(),
				"customer.identify":$("#vip_identify").val(),
				"customer.vip.vipId":$("#vip_vipId").val(),
				"customer.vip.level.id":$("select[name='vip_level'] option:selected").val(),
				"customer.user.phone":$("#vip_phone").val(),
				"page.totalSize":parseInt($("#totalPage").html()),
				"page.currentPage":parseInt($("#currentPage").html())
			},
			contentType:"application/json;charaset=utf-8",
			success:function(result){
				if(result.code==200){
					var content="";
					for(var i=0;i<result.object.data.length;i++){
						var value=result.object.data[i];
						var phone=value.user!=null?value.user.phone:"";
						content+="<tr class='active'>"
						+"<td>"+value.name+"</td>"
						+"<td>"+value.identify+"</td>";
						if(value.user==null){
							content+="<td></td>"
						}else{
							content+="<td>"+value.user.phone+"<a href='' data-toggle='modal' data-target='#updatePhoneModal' onclick='updatePhoneInfo("+value.id+","+value.user.phone+")'>&nbsp<span class='glyphicon glyphicon-pencil'></span></a></td>"
						}
						content+="<td>"+value.createDate+"</td>";
						if(value.vip!=null){
							content+="<td>"+value.vip.vipId+"</td>"
								+"<td>"+value.vip.padmoney+"</td>"
								+"<td>"+value.vip.discout+"<a href='' data-toggle='modal' data-target='#updateDiscountModal' onclick='updateDiscount("+value.id+","+value.vip.discout+")'>&nbsp<span class='glyphicon glyphicon-pencil'></span></a></td>"
								+"<td>"+value.vip.createDate+"</td>"
								+"<td>"+value.vip.level.name+"</td>"
								+"<td></td>";
						}else{
							content+="<td>非会员</td>"
								+"<td></td>"
								+"<td></td>"
								+"<td></td>"
								+"<td></td>"
								+"<td>"
								+"<button type='button' class='btn btn-default btn-xs' data-toggle='modal' data-target='#myModal' onclick='showVipInfo("+value.id+")'>"
						        +"<span class='glyphicon glyphicon-user'></span>创建会员"
						        +"</button></td>";
						}
						content+="</tr>"
					}
					$("#vip_infos").html(content);
					$("#currentPage").html(result.object.currentPage);
					$("#totalPage").html(result.object.totalSize);
				}else{
					alert(result.code);
				}
			}
		});
	}
	function showVipInfo(id){
		$.ajax({
			url:"customer/findCustomerById",
			type:"get",
			data:{
				id:id
			},
			success:function(result){
				$("#vip_name_m").val(result.object.name);
				$("#vip_identify_m").val(result.object.identify);
				$("#vip_id_m").val(result.object.id);
				if(result.object.user!=null){
					$("#vip_phone_m").val(result.object.user.phone);
				}
			}
		});
	}
	function updatePhoneInfo(id,phone){
		$("#vip_id_pm").val(id);
		$("#currentPhone").val(phone);
	}
	function updateDiscount(id,discount){
		$("#vip_id_dm").val(id);
		$("#currentDiscount").val(discount);
	}
</script>
</head>
<body style="background-color: #FFF">
<div class="container" >
	<div class="row clearfix">
		<div class="col-md-12 column">
			<div class="row clearfix inputinfo">
				<div class="col-md-4 column ">
					<div class="input-group">
					<span class="input-group-addon glyphicon">&nbsp;姓名&nbsp;</span>
					 <input type="text" class="form-control" placeholder="姓名查询" id="vip_name">
					</div>
				</div>
				<div class="col-md-4 column ">
					<div class="input-group">
					<span class="input-group-addon glyphicon">&nbsp;身份证</span>
           			 <input type="text" class="form-control" placeholder="身份证查询" id="vip_identify">
           			 </div>
				</div>
				<div class="col-md-4 column ">
					<div class="input-group">
					<span class="input-group-addon glyphicon">会员编号</span>
           			 <input type="text" class="form-control" placeholder="会员编号查询" id="vip_vipId">
           			 </div>
				</div>
			</div>
			<div class="row clearfix inputinfo">
				<div class="col-md-4 column ">
					<div class="input-group">
					   <span class="input-group-addon glyphicon">会员等级</span>
           			  <select class="form-control" name="vip_level" id="vip_level">
           			  	<!-- <option value=""></option>
      					<option value="1">普通会员</option>
     					<option value="2">2</option>
      					<option value="3">3</option>
      					<option value="4">4</option>
      					<option value="5">5</option>
      					<option value="6">6</option>
      					<option value="7">7</option>
      					<option value="8">8</option> -->
    				 </select>
           			 </div>
				</div>
				<div class="col-md-4 column">
					<div class="input-group">
					 <span class="input-group-addon glyphicon ">&nbsp;手机号</span>
           			 <input type="text" class="form-control" placeholder="手机号查询" id="vip_phone">
           			 </div>
				</div>
				<div class="col-md-4 column">
					<a href="javascript:void(0);" class="btn btn-info btn-default" id="searchCustomer">
          				<span class="glyphicon glyphicon-search"></span> 查询
       				</a>
       				<a href="customer/exportExcel" class="btn btn-info btn-default" id="exportExcel">
          				<span class="glyphicon glyphicon-open"></span> 导出
       				</a>
				</div>
			</div>
			<div class="row clearfix inputinfo">
				<div class="col-md-4 column ">
					<form class="form-horizontal" role="form" action="customer/importPM" enctype="multipart/form-data" method="post">
					<div class="form-group">
					<div class="col-sm-4">
					<button class="btn btn-primary btn-sm" type="submit" value="提交">批量更新消费金额</button>
					</div>
					<div class="col-sm-8">
						<input class="form-control " type="file" name="file" >
					</div>
					</div>
       				</form>
				</div>
		</div>
	</div>
	<div class="row" >
		<div class="col-md-12 column table-responsive">
			<table class="table table-striped  table-bordered table-hover" id="table">
				 <thead>
					<tr>
						<th>姓名</th>
						<th>身份证号</th>
						<th>手机号</th>
						<th>创建时间</th>
						<th>会员编号</th>
						<th>消费总金额</th>
						<th>折扣</th>
						<th>入会时间</th>
						<th>会员等级</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody id="vip_infos">
				</tbody> 
			</table>
		</div>
	</div>
	<div class="row clearfix">
		<div class="col-md-12 column">
			<div class="row clearfix">
					<div class="col-md-6 column">
						<div class="btn-group">
							<button type="button" class="btn btn-primary btn-xs" id="firstPage">首页</button>
							<button type="button" class="btn btn-primary btn-xs" id="prePage">上一页
							</button>
							<button type="button" class="btn btn-info btn-xs"
								disabled="disabled">
								<span id="currentPage">1</span>/<span id="totalPage">0</span>
							</button>
							<button type="button" class="btn btn-primary btn-xs" id="nextPage">下一页
							</button>
							<button type="button" class="btn btn-primary btn-xs" id="lastPage">末页</button>
						</div>
					</div>
					<div class="col-md-2 column">
				</div>
				<div class="col-md-4 column">
				</div>
			</div>
		</div>
	</div>
</div>
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">创建会员</h4>
            </div>
				<div class="modal-body">
					<form class="form-horizontal" role="form" >
						<input type="hidden" id="vip_id_m">
						<div class="form-group">
							<label  class="col-sm-2 control-label" id="tesx">姓名：</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="vip_name_m" disabled="disabled" />
							</div>
						</div>
						<div class="form-group">
							<label  class="col-sm-2 control-label">手机号</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="vip_phone_m" disabled="disabled"/>
							</div>
						</div>
						<div class="form-group">
							<label  class="col-sm-2 control-label">身份证</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="vip_identify_m" disabled="disabled"/>
							</div>
						</div>
						<div class="form-group">
							<label  class="col-sm-2 control-label">会员等级</label>
							<div class="col-sm-6">
								<select class="form-control" name="vip_level" id="vip_level_m" disabled="disabled">
									<option value="1">青铜</option>
								</select>
							</div>
						</div>
					</form>
				</div>
				<div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="submit_m">确定</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<!-- 模态框（Modal） -->
<div class="modal fade" id="updatePhoneModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">修改手机号码</h4>
            </div>
            <div class="modal-body">
            <form class="form-horizontal" role="form" >
				<div class="form-group">
					<label class="col-sm-4 control-label" id="tesx">原手机号码：</label>
					<div class="col-sm-6">
						<input type="text" class="form-control" id="currentPhone" disabled="disabled" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-4 control-label" >新手机号码：</label>
					<div class="col-sm-6">
						<input type="text" class="form-control" id="newPhone"/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-4 control-label" id="info_d"></label>
				</div>
				</form>
			</div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="updatePhone">提交更改</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<!-- updateDiscountModal模态框（Modal） -->
<div class="modal fade" id="updateDiscountModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">修改会员折扣</h4>
            </div>
            <div class="modal-body">
            <form class="form-horizontal" role="form" >
				<input type="hidden" id="vip_id_dm">
				<div class="form-group">
					<label class="col-sm-4 control-label" >原折扣：</label>
					<div class="col-sm-6">
						<input type="text" class="form-control" id="currentDiscount" disabled="disabled" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-4 control-label" >新折扣：</label>
					<div class="col-sm-6">
						<input type="text" class="form-control" id="newDiscount"  />
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-4 col-sm-offset-2 control-label" id="info_d" style="color: red"></label>
				</div>
				</form>
			</div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="updatediscount">提交更改</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
</body>
</html>